//
//  SXWYNewsCommonCell.m
//  ShiXun
//
//  Created by lanou on 15/10/26.
//  Copyright © 2015年 张琪. All rights reserved.
//

#import "SXWYNewsCommonCell.h"
#import "UIImageView+WebCache.h"
@implementation SXWYNewsCommonCell
- (void)setConfigureModel:(SXWYNewsMainModel *)configureModel
{
    _configureModel = configureModel;
    [_coverImg sd_setImageWithURL:[NSURL URLWithString:configureModel.imgsrc] placeholderImage:[UIImage imageNamed:@"SX-placeholder"]];
    _titleLabel.text = configureModel.title;
    _contentLabel.text = configureModel.digest;
    [SXWYNewsCommonCell changeLineSpace:_contentLabel];
    _replayLabel.text = configureModel.source;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        CGFloat imgWidth = (kScreenWidth - 30) / 3 - 20;
        _coverImg = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, imgWidth, imgWidth * 20 / 27)];
        [self.contentView addSubview:_coverImg];
        
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imgWidth + 20, 10, kScreenWidth - imgWidth - 30, imgWidth * 20 / 81)];
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        _titleLabel.font = [UIFont systemFontOfSize:15.5];
        [self.contentView addSubview:_titleLabel];
        
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(imgWidth + 20, imgWidth * 20 / 81 + 18, kScreenWidth - imgWidth - 30, imgWidth * 40 / 81)];
        _contentLabel.numberOfLines = 2;
        _contentLabel.font = [UIFont systemFontOfSize:12.5];
        _contentLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_contentLabel];
        
        _replayLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth - 150, imgWidth * 40 / 81 + 14, 140, imgWidth * 20 / 81)];
        _replayLabel.font = [UIFont systemFontOfSize:10];
        _replayLabel.textAlignment = NSTextAlignmentRight;
        _replayLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_replayLabel];
        
    }
    return self;
}
+ (void)changeLineSpace:(UILabel *)label
{
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:label.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:5];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, label.text.length)];
    [label setAttributedText:attributedString];
    [label sizeToFit];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
